package test.algos.multiply;

import java.util.LinkedList;
import java.util.List;

public class MultUtil {

	public static List<Long> extractDigits(Long input, double numberLen) {
		LinkedList<Long> digits = new LinkedList<>();

		long nearestTwoPower = (long) Math.ceil((Math.log(numberLen) / Math
				.log(2)));

		long indexSize = (long) Math.pow(2, nearestTwoPower);

		while (input > 0) {
			digits.push(input % 10);
			input /= 10;
		}

		if (digits.size() < indexSize) {

			for (int i = digits.size(); i < indexSize; i++) {
				digits.push(0L);
			}

		}

		return digits;
	}

	public static Long combineDigits(List<? extends Number> digitsList) {

		Long result = 0L;
		int listSize = digitsList.size() - 1;
		for (int i = 0; i < digitsList.size(); i++) {

			long curInput = (Long) digitsList.get(i);
			result += (long) (Math.pow(10, (listSize - i)) * curInput);
		}
		return result;

	}

	public static Long gaussFormula(Long firstCf, Long secondCf, Long thirdCf,
			int inputLength) {

		long fact1 = (long) (Math.pow(10, inputLength) * firstCf);
		long fact3 = (long) (Math.pow(10, (inputLength / 2)) * thirdCf);

		return fact1 + fact3 + secondCf;

	}

	public static double maxTenPos(Long input1, Long input2) {

		double size1 = (Math.log(input1) / Math.log(10));
		double size2 = (Math.log(input2) / Math.log(10));

		if (size1 > size2) {
			return size1;
		}

		return size2;
	}

}
